/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.geometry;

import ace.system.GameRandom;

/**
 *
 * @author Hallucinogen
 */
public class Vector2D {
	public Vector2D() {
		x = 0;
		y = 0;
	}

	public Vector2D(float inX, float inY) {
		x = inX;
		y = inY;
	}

	public Vector2D(Vector2D otherVector) {
		x = otherVector.x;
		y = otherVector.y;
	}

	public void randomizeVector(Vector2D randomFactor) {
		x = randomFactor.x * GameRandom.floatRandom();
		y = randomFactor.y * GameRandom.floatRandom();
	}

	public void zero() {
		x = 0;
		y = 0;
	}

	public void invert() {
		x = -x;
		y = -y;
	}

	public static Vector2D getVector(Vertex2D v1, Vertex2D v2) {
		return new Vector2D(v2.x - v1.x, v2.y - v1.y);
	}

	public static Vector2D add(Vector2D v1, Vector2D v2) {
		return new Vector2D(v2.x + v1.x, v2.y + v1.y);
	}

	public void add(Vector2D otherVector) {
		x += otherVector.x;
		y += otherVector.y;
	}

	public float getMagnitude() {
		return (float)Math.sqrt(x * x + y * y);
	}

	public String toString() {
		return "(" + x + ", " + y + "}";
	}

	public float x;
	public float y;
}
